# -*- coding:utf-8 -*-
'''
@finish time:20170914
@author;fengjiexyb
this code is used for my lcd digit dataset gray and binarization
'''
import pickle
from svmutil import *
from PCV.tools import imtools
import numpy as np
import struct
import matplotlib.pyplot as plt
import random
import logging
import os
from PIL import Image
import cv2
path='C:/Users/fengjiexyb/Desktop/ttt/'
files=os.listdir(path)
features=[]
label = []
for index in files:
image=Image.open(path+index)
imNew=np.array(image.resize((50,50)).convert('L'))
thresh = 10
maxValue = 255
#binarization used ostu in three lower lines
blur = cv2.GaussianBlur(imNew, (5, 5), 0)
ret3, dst = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
Image.fromarray(dst).save('new' + index, 'jpeg')
# 以下两行二值化的效果不如ostu
# 具体参数参考ht
图像二值化、提取边缘
最新推荐文章于 2024-07-31 18:11:04 发布
这段代码用于LCD数字数据集的灰度和二值化处理。通过OpenCV库,应用高斯模糊、Otsu二值化等方法对图像进行预处理,同时展示了如何使用自适应阈值提取图像边缘。最后,将处理后的图像保存为JPEG格式。
摘要由CSDN通过智能技术生成